import {Modal} from 'antd';
import isFunction from 'lodash/isFunction';
import {WeaLocaleProvider} from 'ecCom';
import './style/logItem.less'
import {createReplyBottomAtt} from '../../util/communicationUtil';
const getLabel = WeaLocaleProvider.getLabel;


class ReplyItem extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    const { replyInfo,  isprint = '0', isFromPortal = false, hasSubmitRight = false} = this.props; 
    const { discussantInfo = {},remark , showDate, id,  createUserName, 
    createUser, resiveUser, resiveUserName, canModify, isAnonymous, 
    relatedaccList4E9 = [], relatedcusList4E9 = [], relateddocList4E9 = [], relatedprjList4E9 = [], relatedwfList4E9 = [], relatemutilprjs4E9 = [],
    createUserType = '1', resiveUserType = '1'
  } = replyInfo;
    return (
      <div className="wea-cowork-reply-item">
        <div className="reply-item-content">
          <div className='operate-hd'>
            <span className="cowork-reply-user">
                {
                  isAnonymous == 1 
                  ? <span >{discussantInfo.lastname}</span>
                  :  <React.Fragment>
                    { createUserType == '1' && <a  href={`javaScript:openhrm(${createUser});`} onClick={window.pointerXY}>{createUserName}</a> }
                    { createUserType == '2' &&  <a href={`javaScript: window.open('/spa/crm/static/index.html#/main/crm/customerView?customerId=${createUser}&_key=jfzmyh', '_blank')`}>{createUserName}</a>}
                  </React.Fragment>
                }
                {
                  resiveUser > -1  
                  && (
                    <span>
                      <span className="ml5">{getLabel(128123, '回复')}</span>
                      {resiveUserType == '1' && <a className="ml5" href={`javaScript:openhrm(${resiveUser});`} onClick={window.pointerXY} >{resiveUserName}</a>}
                      {resiveUserType == '2' && <a className="ml5" href={`javaScript: window.open('/spa/crm/static/index.html#/main/crm/customerView?customerId=${resiveUser}&_key=jfzmyh', '_blank')`} >{resiveUserName}</a>}
                    </span>
                    )
                }
                <span className="reply-time">{showDate}</span>
              </span>
            <span className="fr">
              {isprint == '0' && canModify && !isFromPortal && hasSubmitRight && <span className="cowork-top-icon icon-coms-delete" onClick={this.delete} title={getLabel(91,'删除')}/>}
              {isprint == '0' && !isFromPortal && hasSubmitRight && <span 
                className="cowork-top-icon icon-coms-New-SMS" 
                onClick={this.props.reply.bind(this, id, createUser,createUserName,createUserType,'reply')} 
                title={getLabel(128123, '回复')}
                />
              }
            </span>
          </div>
          <div className="cowork-reply-remark wea-f12">
            <div
              className="wea-cl-content"
              dangerouslySetInnerHTML={{__html: `<div class="wea-ckeditor-content">${remark}</div>`}}
            />
          </div>
          <div className="workflow-resource-list">
            {createReplyBottomAtt(getLabel(857, '相关文档')+':',relateddocList4E9, ()=>{}, "doc")}
            {createReplyBottomAtt(getLabel(1044, '相关流程') + ':',relatedwfList4E9, ()=>{}, "wf")}
            {createReplyBottomAtt(getLabel(783, '相关客户') + ':',relatedcusList4E9, ()=>{}, "crm")}
            {createReplyBottomAtt(getLabel(782, '相关项目') + ':',relatemutilprjs4E9, ()=>{}, "project")}
            {createReplyBottomAtt(getLabel(33414, '相关任务')+':',relatedprjList4E9, ()=>{}, "task")}
            {createReplyBottomAtt(getLabel(33414, '相关附件')+':',relatedaccList4E9, ()=>{}, "acc")}
          </div>
        </div>
      </div>
    );
  }
  
  delete = () => {
    let that = this;
    const { changePageNum, operate, logid, replyInfo } = this.props;
    const { id } = replyInfo;
    Modal.confirm({
      content: getLabel(512301, '确认要删除该评论吗？'),
      onOk() {
        changePageNum();
        isFunction(operate) && operate({
          id: id,
          operationType: 'delReply'
        }, logid);
      }
    });
  }
}

export default ReplyItem;